package Multithreading.ThreadPool.ThreadPoolDome001;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * ClassName:ThreadPool002
 * Package:Multithreading.ThreadPool
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/7-16:55
 * @Version:v1.0
 */
public class ThreadPool002 {
    // public static ExecutorService newCachedThreadPool() 创建一个没有上限的线程池
    // public static ExecutorService newFixedThreadPool(int nThreads) 创建有上限的线程池、
    public static void main(String[] args) throws InterruptedException {
        //获取线程池对象
//        ExecutorService pool1 = Executors.newCachedThreadPool();
        ExecutorService pool1= Executors.newFixedThreadPool(3);
        //提交任务
        pool1.submit(new MyRunnable001());
        pool1.submit(new MyRunnable001());
        pool1.submit(new MyRunnable001());
        pool1.submit(new MyRunnable001());
        pool1.submit(new MyRunnable001());
        //销毁线程池
       pool1.shutdown();
    }
}
